#include <iostream>

using namespace std;

unsigned int palin(unsigned int k)
{
	unsigned int res = 0;
	while (k > 0)
	{	
		int d = k % 10;
		res = res * 10 + d;
		k /= 10;
	}
	return res;
}

bool isPalin(unsigned int k)
{
	unsigned int res = 0;
	unsigned int kk = k;
	while (k > 0)
	{	
		int d = k % 10;
		res = res * 10 + d;
		k /= 10;
	}
	return (res == kk);
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) 
	{
		unsigned int m;
		cin >> m;
		
		int count = 0;
		while (!isPalin(m))
		{
			m = m + palin(m);	
			count ++;
		}
		
		cout << count << " " << m << endl;
	}

	return 0;
}
